package com.fauks.crm.service.impl;

import com.fauks.crm.mapper.CustomerMapper;
import com.fauks.crm.pojo.Customer;
import com.fauks.crm.pojo.QueryVo;
import com.fauks.crm.service.CustomerService;
import com.fauks.crm.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public Page<Customer> getCustomerByQueryVo(QueryVo queryVo) {
        //设置分页开始的下标
        queryVo.setStart((queryVo.getPage() - 1) * queryVo.getRows());
        //获取总记录数
        Integer count = customerMapper.getCountByQueryVo(queryVo);
        List<Customer> customerList = customerMapper.getCustomByQueryVo(queryVo);
        //包装分页数据
        Page<Customer> page = new Page<Customer>(count, queryVo.getPage(), queryVo.getRows(), customerList);
        return page;
    }

    @Override
    public Customer getCustomerById(Integer id) {
        return customerMapper.getCustomerById(id);
    }

    @Override
    public void updateCustomer(Customer customer) {
        customerMapper.updateCustomer(customer);
    }
}
